<?php
//包含数据库配置文件
include '../../public/dbconfig.php';
//包含函数库文件
include '../../public/functions.php';
//调用函数 链接数据库
$link = con();

//接收用户需要修改的id
$fid = $_POST['fid'];
//接收友链标题
$username = $_POST['username'];
//接收友链地址
$url = $_POST['url'];
//友链描述
$keywords = $_POST['keywords'];
//判断用户是否上传logo
if($_FILES['logo']['error'] != 4){
	//调用上传函数
	$newname = upload('logo','../../home/images/');
	//调用缩放函数
	suofang('../../home/images/'.$newname,130,65);
	$logo = $newname;
}else{
	//如果用户没有上传图像 就用原来的 通过隐藏域传过来
	$logo = $_POST['logo'];
}

//准备sql
$sql = "update friends set username='{$username}',url='{$url}',keywords='{$keywords}',logo='{$logo}' where id={$fid}";
//执行sql
$res = mysqli_query($link, $sql);
//判断执行结果
if($res){
	echo '<script>alert("修改成功");window.location.href="list.php"</script>';
}else{
	echo '<script>alert("修改失败");window.location.href="edit.php?fid='.$fid.'"</script>';
}
//关闭数据库链接
mysqli_close($link);